#include "childthread.h"

childThread::childThread() {
    ctool=new class ctool(this);
}

childThread::childThread(QTcpSocket *clientTcpSocket,QObject *parent):QThread(parent)
{
    setClientTcpSocket(clientTcpSocket);
    // childThread();
    ctool=new class ctool(this);
    // clientTcpSocket->moveToThread(this);
}

void childThread::run()
{
    // qDebug()<<"1111";
    connect(clientTcpSocket,&QTcpSocket::disconnected,this,[this](){
        clientTcpSocket->deleteLater();
        clientTcpSocket=nullptr;
        exit();
        this->deleteLater();
        qDebug()<<"client is died";
        // exit();
    });
    connect(clientTcpSocket,&QTcpSocket::readyRead,this,[this](){
        QByteArray InforOfclientTcpSocket=clientTcpSocket->readAll();
        QByteArrayList byteArrayListToSend= ctool->processingCommunicationInformationCenter(InforOfclientTcpSocket);

        for(QByteArray i:byteArrayListToSend){
            clientTcpSocket->write(i+dedicatedDelimiter);
        }
    });
    exec();
}

void childThread::setClientTcpSocket(QTcpSocket *newClientTcpSocket)
{
    clientTcpSocket = newClientTcpSocket;
}

const QSqlDatabase *childThread::getDb() const
{
    return db;
}

void childThread::setDb(const QSqlDatabase *newDb)
{
    db = newDb;
}
